package com.myteam.mystory.adapter;

import com.myteam.mystory.R;

import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.view.animation.TranslateAnimation;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TopViewAdapter extends BaseAdapter implements OnClickListener {
	private LayoutInflater mInflater;
	private String[] data;
	TranslateAnimation translateAnimation;
	
	public TopViewAdapter(Context context) { 
		mInflater = LayoutInflater.from(context);
	}

	public void setData(String[] data) {
		this.data = data;
	}
	
	@Override
	public int getCount() {
		return data.length;
	}

	@Override
	public Object getItem(int item) {
		return data[item];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView	= mInflater.inflate(R.layout.topview_adapter, null);
			holder = new ViewHolder();
			holder.mTitleText	= (TextView) convertView.findViewById(R.id.topview_namestory);
			holder.topview_author = (TextView) convertView.findViewById(R.id.topview_nameauthor);
			holder.topview_img = (ImageView) convertView.findViewById(R.id.topview_img);
			holder.topview_bookmark = (ImageView) convertView.findViewById(R.id.topview_bookmark);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.mTitleText.setText(data[position]);
		
		translateAnimation = new TranslateAnimation(130, 0, 50, 0);// phai sang,trai sang, duoi len, tren xuong
		translateAnimation.setDuration(300);
		
		convertView.startAnimation(translateAnimation);
		
		return convertView;
	}

	static class ViewHolder {
		TextView mTitleText;
		ImageView topview_img;
		TextView topview_author;
		ImageView topview_bookmark;
	}

	@Override
	public void onClick(DialogInterface dialog, int which) {
		
	}
}